const {
  toUrl,globalData
} = getApp();
import {
  request
} from "@/utils/request";
Page({
  toUrl,
  show: false,
  data: {
    globalData,
    width30: 10,
    orderList: [{
        type: 0,
        title: "全部",
        icon: "/image/image32.png",
        url: "/pages/order/list"
      },
      {
        type: 1,
        title: "待使用",
        icon: "/image/image33.png",
        url: "/pages/order/list"
      },
      {
        type: 2,
        title: "已完成",
        icon: "/image/image34.png",
        url: "/pages/order/list"
      },
      {
        type: 3,
        title: "已退款",
        icon: "/image/image35.png",
        url: "/pages/order/list"
      },
    ],
    menus: [{
        title: "积分商城",
        icon: "/image/image37.png",
        url: "./score/list",
        tab: "toUrl",
        is_report: 1,
      },
      {
        title: "拍照积分",
        icon: "/image/image38.png",
        url: "./score/takePhone/form",
        tab: "toUrl",
        is_report: 1,
      },
      {
        title: "积分抽奖",
        icon: "/image/image39.png",
        url: "./score/raffle/raffle",
        tab: "toUrl",
        is_report: 1,
      },
      {
        title: "我的报名",
        icon: "/image/image40.png",
        url: "/pages/activity/myList",
        tab: "toUrl",
        is_report: 1,
      },
      {
        title: "完善资料",
        icon: "/image/image41.png",
        url: "/pages/me/detail",
        tab: "toUrl",
        is_report: 1,
      },
      {
        title: "商家核销",
        icon: "/image/image42.png",
        url: "/pages/order/detail",
        tab: "scan",
        is_report: 1,
      },
      {
        title: "联系客服",
        icon: "/image/image43.png",
        url: "",
        tab: "makePhoneCall",
        is_report: 1,
      },
      {
        title: "用户反馈",
        icon: "/image/image44.png",
        url: "./feedback/form",
        tab: "toUrl",
        is_report: 1,
      },
      {
        title: "商家报表",
        icon: "/img/me32.png",
        url: "/pages/me/storeform/storeform",
        tab: "toUrl",
        is_report: 0
      },
     
     
    ],
    userInfo: {},
    baseUrl: "/image/mebg.png",
    signIntegral: "",
    is_report: 0
    // integral: {} //积分
  },
  handleDetail(){
    wx.navigateTo({
      url: '/pages/me/sigin/me',
    })
  },
  platenumSuccess(e){
    console.log(e);
  },
      //处理头部滚动事件
      onPageScroll(e) {
        const scrollTop = e.scrollTop
        if (scrollTop > 80) {
            this.setData({
                headBc: 'headbc',
                act: '/image/icon-arrow-left.png'
            })
        } else {
            this.setData({
                headBc: '',
                act: '/img/act3.png'
            })
        }
    },
  //拨打电话
  makePhoneCall() {
    let userInfo = this.data.userInfo;
    if (userInfo) {
      wx.makePhoneCall({
        phoneNumber: this.data.userInfo.kefu, //仅为示例，并非真实的电话号码
      });
    } else {
      wx.redirectTo({
        url: "/pages/login/login",
      });
    }
  },

  getUserInfo1() {
    // 假设在一个按钮的点击事件中获取用户昵称
    wx.getUserInfo({
      success: res => {
        const nickname = res.userInfo;
      },
      fail: error => {
        console.error(error);
      }
    });
  },
  bindgetuserinfo() {
    wx.getUserProfile({
      desc: '获取用户昵称',
      success: res => {
        const nickname = res.userInfo.nickName;
      },
      fail: error => {
        console.error(error);
      }
    });
  },
  scan() {
    wx.scanCode({
      success: (res) => {
        const {
          result
        } = res;
        let data = JSON.parse(result);
        request("order/writeoffcodetoid", {
          data: {
            writeoff_code: data.writeoff_code
          },
        }).then((res) => {
          if (res.errcode == 1) {
            wx.redirectTo({
              url: `/pages/order/detail?order_id=${res.data.order_id}&admins=1`,
            });
          } else {
            wx.showToast({
              title: res.message,
            });
            setTimeout(() => {
              wx.navigateBack({
                delta: 1,
              });
            }, 200);
          }
        });
      },
    });
  },
  signIn() {
    request("integral/signin").then((res) => {
      if (res.errcode == 1) {
        this.show();
        this.getInFo();
        this.setData({
          signIntegral: res.data.integral,
        });
      }
    });
  },
  getInFo() {
    const that = this
    request("user/getuserinfo").then((res) => {
      getApp().globalData.baseInfo = res.data;
      let userInfo = res.data;
      const menu = that.data.menus
      const len = menu.length
      // menu[len -1]['is_report'] = res.data.is_report
      // menu[len -1]['is_report'] = res.data.is_report
      this.setData({
        userInfo,
        menus: menu,
        baseUrl: getApp().globalData.baseUrl + "static/images/me11.png",
      });
    });
  },
  show() {
    this.setData({
      show: !this.data.show
    });
  },
  onLoad(options) {
    this.getInFo();
  },

  onShow() {
    this.getInFo()
    this.setData({
      userInfo: getApp().globalData.baseInfo,
      baseUrl: getApp().globalData.baseUrl + "/static/images/me11.png",
    });
  },

});